﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display.LotUI {
    import flash.events.*;
    import flash.display.*;
    import flash.geom.*;
    import org.aswing.*;
    import Classes.*;
    import Classes.sim.*;
    import com.greensock.*;
    import ZLocalization.*;
    import Display.FactoryUI.*;
    import Classes.orders.*;
    import Display.aswingui.*;
    import L10n.*;

    public class LotSlidePick extends SlidePick {

        public static const MARGIN_WIDTH:int = 30;
        public static const BUTTON_HEIGHT:int = 25;
        public static const INFO_PANE_HEIGHT:int = 30;
        public static const STATE_CLOSED:int = 0;
        public static const STATE_ACCEPT:int = 1;
        public static const STATE_TOASTER:int = 2;

        protected var m_state:int;
        protected var m_info:JLabel;
        protected var m_info2:JLabel;
        protected var m_amountLabel:JLabel;
        protected var m_jLabel:JLabel;
        protected var m_lotManager:LotManager;
        protected var m_order:LotOrder;
        protected var m_uiHandle:int;
        protected var m_senderName:String;
        protected var m_acceptBtn:CustomButton;
        protected var m_laterBtn:CustomButton;
        protected var m_declineBtn:CustomButton;

        public function LotSlidePick(_arg1:LotManager, _arg2:LotOrder, _arg3:Boolean=true, _arg4:Boolean=false, _arg5:int=0, _arg6:Boolean=false, _arg7:int=-1){
            this.m_order = _arg2;
            this.m_lotManager = _arg1;
            this.m_uiHandle = 1;
            this.m_info = null;
            this.m_amountLabel = null;
            this.m_state = STATE_CLOSED;
            var _local8:String = _arg2.getSenderID();
            var _local9:Player = Global.player.findFriendById(_local8);
            var _local10:String = (_local9) ? _local9.snUser.picture : null;
            this.m_senderName = (_local9) ? _local9.firstName : "";
            var _local11:String = ((this.m_order.getOrderResourceName()) || (ZLoc.t("Items", (this.m_order.getResourceType() + "_friendlyName"))));
            var _local12:String = ZLoc.t("Dialogs", "lotOrder_accept_message", {
                name:ZLoc.tn(this.m_senderName),
                businessName:_local11
            });
            this.m_jLabel = new JLabel(_local12);
            this.m_jLabel.setFont(ASwingHelper.getBoldFont(14));
            LocaleHelper.localSetting.JLabel_setFont(this.m_jLabel, EmbeddedArt.SYSTEM_FONT, 14);
            LocaleHelper.localSetting.ASwingHelper_setEasyBorder(this.m_jLabel, 0, 0, 5);
            ASwingHelper.prepare(this.m_jLabel);
            super(_local10, _arg3, _arg4, _arg5, false, (this.m_jLabel.width + (2 * MARGIN_WIDTH)));
            addEventListener(MouseEvent.MOUSE_MOVE, this.stopMousePropagation, false, 0, true);
            addEventListener(MouseEvent.MOUSE_OUT, this.stopMousePropagation, false, 0, true);
            addEventListener(MouseEvent.MOUSE_OVER, this.stopMousePropagation, false, 0, true);
            addEventListener(MouseEvent.CLICK, this.onMouseClick, false, 0, true);
        }
        protected function stopMousePropagation(_arg1:MouseEvent):void{
            _arg1.stopPropagation();
            _arg1.stopImmediatePropagation();
        }
        protected function onMouseClick(_arg1:MouseEvent):void{
            var _local3:LotSite;
            var _local4:SlidePickGroup;
            var _local2:Number = (this.order) ? this.order.getLotId() : 0;
            if (_local2){
                _local3 = Global.world.citySim.lotManager.getLotSite(_local2);
                if (_local3){
                    _local4 = (_local3.getPick() as SlidePickGroup);
                    if (_local4){
                        _local4.onClick();
                    };
                };
            };
        }
        public function getPickSprite():Sprite{
            return (this.m_mainSprite);
        }
        override public function getMainSpriteRect(_arg1:DisplayObject):Rectangle{
            var _local2:Rectangle = super.getMainSpriteRect(_arg1);
            if (((m_innerSprite.visible) && ((m_innerSprite.x == 0)))){
                _local2.width = (_local2.width + slideWidth);
            };
            return (_local2);
        }
        override protected function getPickBackground():Class{
            return (EmbeddedArt.trainUIPick);
        }
        override protected function getInnerBackground():Class{
            return (EmbeddedArt.trainUIBG);
        }
        override protected function initInner():void{
            super.initInner();
            var _local1:JPanel = ASwingHelper.makeSoftBoxJPanelVertical(AsWingConstants.CENTER);
            _local1.setPreferredWidth(slideWidth);
            var _local2:JPanel = ASwingHelper.makeSoftBoxJPanel(AsWingConstants.CENTER);
            _local2.setPreferredWidth(slideWidth);
            _local2.setPreferredHeight(INFO_PANE_HEIGHT);
            var _local3:JPanel = ASwingHelper.makeSoftBoxJPanel(AsWingConstants.CENTER, 10);
            this.m_acceptBtn = new CustomButton(ZLoc.t("Dialogs", "Accept"), null, "GreenSmallButtonUI");
            this.m_acceptBtn.setPreferredHeight(BUTTON_HEIGHT);
            this.m_acceptBtn.addActionListener(this.onAccept, 0, true);
            _local3.append(this.m_acceptBtn);
            this.m_laterBtn = new CustomButton(ZLoc.t("Dialogs", "TrainUI_Later"), null, "OrangeSmallButtonUI");
            this.m_laterBtn.setPreferredHeight(BUTTON_HEIGHT);
            this.m_laterBtn.addActionListener(this.onLater, 0, true);
            _local3.append(this.m_laterBtn);
            this.m_declineBtn = new CustomButton(ZLoc.t("Dialogs", "TrainUI_Decline"), null, "RedSmallButtonUI");
            this.m_declineBtn.setPreferredHeight(BUTTON_HEIGHT);
            this.m_declineBtn.addActionListener(this.onDecline, 0, true);
            _local3.append(this.m_declineBtn);
            _local2.appendAll(ASwingHelper.horizontalStrut(MARGIN_WIDTH), this.m_jLabel);
            ASwingHelper.prepare(_local2);
            ASwingHelper.prepare(_local3);
            _local1.appendAll(_local2, _local3);
            ASwingHelper.prepare(_local1);
            innerAppendAll(_local1);
        }
        protected function makeAssets(_arg1:DisplayObject, _arg2:String):void{
            this.openInnerPane();
        }
        protected function fn():LocalizationName{
            var _local1:String;
            var _local2:String = ((this.m_order.getTransmissionStatus() == OrderStatus.SENT)) ? this.m_order.getRecipientID() : this.m_order.getSenderID();
            _local1 = Global.player.getFriendFirstName(_local2);
            if (_local1 == null){
                _local1 = "???";
            };
            return (ZLoc.tn(_local1));
        }
        protected function buildAndShowInnerPane():void{
            this.rebuildInner();
            this.showInnerPane();
        }
        public function get order():LotOrder{
            return (this.m_order);
        }
        public function openInnerPane():void{
            if (m_sliderActive){
                TweenLite.to(m_innerSprite, 0.5, {
                    x:m_offXPos,
                    onComplete:this.buildAndShowInnerPane
                });
            };
        }
        public function closeInnerPane():void{
            if (m_sliderActive){
                TweenLite.to(m_innerSprite, 0.5, {x:m_offXPos});
            };
        }
        public function backOnePanel():void{
            if (this.m_state == STATE_TOASTER){
                this.m_state = STATE_ACCEPT;
                this.openInnerPane();
            };
        }
        private function removeButtonListeners():void{
            if (this.m_acceptBtn){
                this.m_acceptBtn.removeActionListener(this.onAccept);
            };
            if (this.m_laterBtn){
                this.m_laterBtn.removeActionListener(this.onLater);
            };
            if (this.m_declineBtn){
                this.m_declineBtn.removeActionListener(this.onDecline);
            };
        }
        protected function onAccept(_arg1:Event):void{
            this.removeButtonListeners();
            if (((!(this.m_lotManager)) || (!(this.m_order)))){
                this.kill();
            };
            if (this.m_order.getState() == OrderStates.PENDING){
                this.kill(this.lotManagerAccepted);
            };
        }
        protected function lotManagerAccepted():void{
            var _local1:MapResource = this.m_lotManager.accepted(this.m_order);
            var _local2:Business = (_local1 as Business);
            FranchiseViralManager.triggerFranchiseViralFeeds(FranchiseViralManager.VIRAL_ACCEPTEDBUILDING, this.m_order.getResourceType(), this.m_order.getSenderID(), null, 0, _local2);
        }
        protected function onLater(_arg1:Event):void{
            this.removeButtonListeners();
            this.kill(this.lotManagerLater);
        }
        protected function lotManagerLater():void{
            this.m_lotManager.later(this.m_order);
        }
        protected function onDecline(_arg1:Event):void{
            this.removeButtonListeners();
            this.kill(this.lotManagerDeclined);
        }
        protected function lotManagerDeclined():void{
            this.m_lotManager.declined(this.m_order);
            var _local1:MapResource = this.m_lotManager.accepted(this.m_order);
            var _local2:Business = (_local1 as Business);
            FranchiseViralManager.triggerFranchiseViralFeeds(FranchiseViralManager.VIRAL_DECLINEDBUILDING, this.m_order.getResourceType(), this.m_order.getSenderID(), null, 0, _local2);
        }

    }
}//package Display.LotUI 
